-- +goose Up
-- +goose StatementBegin
create table if not exists usercategories
(
    id      integer generated by default as identity primary key,
    user_id integer not null references users (id) on delete cascade,
    name    text    not null
        constraint usercategories_name_check
            check (name <> ''::text)
);

comment on table usercategories is 'Категории расходов пользователей';

-- Индекс по пользователю и наименованию категории (lower для регистронезависимого поиска).
create unique index if not exists usercategories_user_id_lower_name
    on usercategories (user_id, lower(name));
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
drop index usercategories_user_id_lower_name;
DROP TABLE IF EXISTS "usercategories";
-- +goose StatementEnd